The following methodology and function parameters are based directly on Jenna Vergeynst’s Python code.
Highlighted blocks are quotes from Jenna’s repository.
Use this code to synchronize receivers based on detection times of synchronization transmitters (‘sync-tags’).
The synchronized times can then be processed into a TOA matrix and fed into YAPS to get estimated locations.
Note that the following synchronization process assumes that the sync-tags are embedded within their resepctive receivers (i.e., are not spatially separated).
# Disable scientific notation
options(scipen=999)
# Print microseconds when viewing the data
sigFiguresSec = 20
options(digits.secs=sigFiguresSec)
# Import custom R functions
for (f in list.files('../code', pattern='*.R')) {
source(paste0('../code/', f))
}
pkg_run(list(
'lubridate',
c('data.table', '1.12.0'),
'dygraphs'),
load_verbose = FALSE,
inst_verbose = TRUE)The following sample data for base_rec and other_rec were converted from pickle into csv.
base_rec_path = '../data/example_base_461059_jv.csv'
other_rec_path = '../data/example_rec_461211_jv.csv'
data_tz = 'GMT'
# same as data_tz = 'UTC'
Sys.setenv(TZ = data_tz)base_receiver = fread(base_rec_path, sep = ',', header = TRUE)[,
Time := ymd_hms(Time, tz = data_tz)]
other_receiver = fread(other_rec_path, sep = ',', header = TRUE)[,
Time := ymd_hms(Time, tz = data_tz)]Total rows base_receiver: 2,262,484
Total rows other_receiver: 2,163,807
## Time ID
## 1: 2018-05-01 00:00:03.481616 65001
## 2: 2018-05-01 00:00:06.686088 62209
## 3: 2018-05-01 00:00:08.906914 62215
## 4: 2018-05-01 00:00:10.483454 62214
## 5: 2018-05-01 00:00:13.689360 62211
## 6: 2018-05-01 00:00:13.776442 62059
orec_osync = add_dtd(b_rec_data = base_receiver,
o_rec_data = other_receiver,
sync_id = osync_id,
dt_cols = 'Time',
id_cols = 'ID',
t_sec = 100)NOTE: The spline method (and the k_par and s_par paramters) used here (smooth.spline) is different from the one in Jenna’s code (Scipy’s UnivariateSpline), but results should be fairly similar
spline_groups = model_spline_part(orec_osync, target_data = other_receiver, dt_cols = dt_col,
gap_lim = 0.1, k_par = 5, s_par = 5e-4)dg_plot(merge(x = spline_groups, y = orec_osync, all = TRUE),
dt_col = dt_col,
y_cols = c('spline', 'dtd_smooth'),
main = 'DTD spline of other rec sync-tag',
plot_subset = 20,
line_w = 0.7)orec_bsync = add_dtd(b_rec_data = base_receiver,
o_rec_data = other_receiver,
sync_id = bsync_id,
dt_cols = 'Time',
id_cols = 'ID',
t_sec = 100)dg_plot(merge(x = spline_groups, y = orec_bsync, all = TRUE),
dt_col = dt_col,
y_cols = c('spline', 'dtd_smooth'),
main = 'DTD spline of base rec sync-tag',
plot_subset = 50,
line_w = 0.7)other_receiver[, spline := (spline_bsync + spline_osync) / 2] %>%
dt_linear_interp(dt_col, 'spline')orec_osync = add_dtd(b_rec_data = base_receiver,
o_rec_data = other_receiver,
sync_id = osync_id,
dt_cols = c(dt_col, 'synced_time'),
t_sec = 100)
smooth_dtd(orec_osync,
outlier_lim = 0.001,
window_size = 6)
orec_bsync = add_dtd(b_rec_data = base_receiver,
o_rec_data = other_receiver,
sync_id = bsync_id,
dt_cols = c(dt_col, 'synced_time'),
t_sec = 100)
smooth_dtd(orec_bsync,
outlier_lim = 0.001,
window_size = 6)## R version 3.6.0 (2019-04-26)
## Platform: x86_64-apple-darwin15.6.0 (64-bit)
## Running under: macOS High Sierra 10.13.6
##
## Matrix products: default
## BLAS: /Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libRblas.0.dylib
## LAPACK: /Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libRlapack.dylib
##
## locale:
## [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
##
## attached base packages:
## [1] stats graphics grDevices utils datasets methods base
##
## other attached packages:
## [1] dygraphs_1.1.1.6 data.table_1.12.2 lubridate_1.7.4
##
## loaded via a namespace (and not attached):
## [1] Rcpp_1.0.1 lattice_0.20-38 zoo_1.8-5 digest_0.6.18
## [5] grid_3.6.0 jsonlite_1.6 magrittr_1.5 evaluate_0.13
## [9] stringi_1.4.3 xts_0.11-2 rmarkdown_1.12 tools_3.6.0
## [13] stringr_1.4.0 htmlwidgets_1.3 xfun_0.6 yaml_2.2.0
## [17] parallel_3.6.0 compiler_3.6.0 htmltools_0.3.6 knitr_1.22